#include <iostream>

template <typename T>
void myFunction(T arg) {
    std::cout << arg << "\n";
};

class greater_than{
    public:
        greater_than(int value) : m_value(value)
        {

        }
        bool operator()(int arg) const
        {
            return arg > m_value;
        }

     private:
        int m_value;
};

//模板类的基本结构
template <typename Function, typename SecondArgType> class partial_application_bind2nd_impl {
    public:
     partial_application_bind2nd_impl(Function function, SecondArgType second_arg): m_function(function) , m_second_arg(second_arg)
        {

        }
      template <typename FirstArgType>
      auto operator()(FirstArgType&& first_arg) const ->
        decltype(m_function(
            std::forward<FirstArgType>(first_arg),m_second_arg))
        {
            //保存的值作为函数的第二个参数
            return m_function(std::forward <FirstArgType> (first_arg), m_second_arg);
        }
     private:
        Function m_function;
        SecondArgType m_second_arg;
};

template <typename Function, typename SecondArgType>
partial_application_bind2nd_impl<Function, SecondArgType>
bind2nd(Function && function,SecondArgType && second_arg)
{
    return(partial_application_bind2nd_impl<Function, SecondArgType>(
        std::forward<Function>(function), std::forward<SecondArgType>(second_arg)));
    
}

int main(int argc, char *argv[])
{
    myFunction(42);
    greater_than greater_than_24(24);
    std::cout << greater_than_24(1)<< "\n";
    std::cout << greater_than_24(50)<< "\n";
    auto greater_than_42 = bind2nd(std::greater<int>(),42);
    std::cout << greater_than_42(2)<< "\n";
    std::cout << greater_than_42(50)<< "\n";
    return 0;
}